package com.zhentao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zhentao.entity.UserVip;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 用户VIP记录Mapper接口
 */
@Mapper
public interface UserVipMapper extends BaseMapper<UserVip> {
    
    /**
     * 查询用户当前生效的VIP记录
     */
    @Select("SELECT * FROM user_vip WHERE user_id = #{userId} AND status = 1 " +
            "AND end_time > NOW() ORDER BY end_time DESC LIMIT 1")
    UserVip selectActiveVipByUserId(@Param("userId") Long userId);
}


